package ace.module.account.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.module.account.api.model.dto.IamApplicationOauth2ClientDto;
import ace.module.account.core.impl.dao.entity.IamApplicationOauth2Client;
import ace.module.account.core.impl.manager.IamApplicationOauth2ClientManager;
import ace.module.account.core.impl.manager.cache.IamApplicationOauth2ClientCacheManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 账户应用与oauth2客户端关系 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class IamApplicationOauth2ClientManagerImpl
    extends AbstractSpringDtoManager<IamApplicationOauth2Client, Long, IamApplicationOauth2ClientDto>
    implements IamApplicationOauth2ClientManager {

  private final IamApplicationOauth2ClientCacheManager iamApplicationOauth2ClientCacheManager;

  private final MessageSourceAssertService assertService;

  @Override
  public IamApplicationOauth2Client getByIdOfClientIdAndDeleteFlagIsFalse(String idOfClient) {
    return iamApplicationOauth2ClientCacheManager.getByIdOfClientIdAndDeleteFlagIsFalse(idOfClient);
  }

  @Override
  public IamApplicationOauth2Client getAndCheckNotNullByIdOfClientIdAndDeleteFlagIsFalse(String idOfClient) {
    IamApplicationOauth2Client iamApplicationOauth2Client = iamApplicationOauth2ClientCacheManager.getByIdOfClientIdAndDeleteFlagIsFalse(idOfClient);
    this.checkNotNull(iamApplicationOauth2Client);
    return iamApplicationOauth2Client;
  }


  private void checkNotNull(IamApplicationOauth2Client iamApplicationOauth2Client) {
    assertService.isNull(iamApplicationOauth2Client, IamApplicationOauth2Client.class.getName() + ".data-not-exist", "账户应用与oauth2客户端关系不存在");
  }
}
